package com.ruoyi.quartz.task;

import com.ruoyi.common.modbus.utils.CacheUtils;
import com.ruoyi.system.config.IotModbusServerConfig;
import com.ruoyi.system.domain.IotGateway;
import com.ruoyi.system.domain.vo.IotDeviceVo;
import com.ruoyi.system.domain.vo.IotGatewayVo;
import com.ruoyi.system.service.IIotDeviceService;
import com.ruoyi.system.service.IIotGatewayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;

/**
 * 定时任务调度测试
 * 公司名称：未可自动化 <br/>
 * 作者：weikeauto <br/>
 */
@Slf4j
@Component("ryTask")
public class RyTask
{

    @Autowired
    private IotModbusServerConfig iotModbusServerConfig;

    @Autowired
    private IIotDeviceService iIotDeviceService;

    @Autowired
    private IIotGatewayService iIotGatewayService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() throws InterruptedException {
        System.out.println("执行无参方法");
        System.out.println(CacheUtils.map);
        List<IotDeviceVo> iotDeviceVoList = iIotDeviceService.selectOnLineIotDeviceList();
        for (IotDeviceVo iotDeviceVo : iotDeviceVoList) {
            log.info("定时任务采集数据：sn=" + iotDeviceVo.getSn());
            iotModbusServerConfig.getMiiServer().sender().testIot(iotDeviceVo.getSn(), iotDeviceVo.getSlaveAddress());
            Thread.sleep(2000);
        }
    }

    public void ryLocationNoParams() throws InterruptedException { // ryTask.ryLocationNoParams
        System.out.println("执行无参方法");
        System.out.println(CacheUtils.map);
//        List<IotDeviceVo> iotDeviceVoList = iIotDeviceService.selectOnLineIotDeviceList();
        List<IotGateway> iotGatewayList = iIotGatewayService.selectAllIotGatewayList();
        for (IotGateway iotGateway : iotGatewayList) {
            log.info("定时任务获取定位数据：sn=" + iotGateway.getSn());
//            iotModbusServerConfig.getMiiServer().sender().testIot(iotDeviceVo.getSn(), iotDeviceVo.getSlaveAddress());
            iotModbusServerConfig.getMiiServer().sender().testIotLocation(iotGateway.getSn(), 1);
            Thread.sleep(2000);
        }
    }


}
